package com.dchh.android.suverynew.module.http.impl;

import com.alibaba.fastjson.JSONObject;
import com.dchh.android.suverynew.common.ICommonModelListener;
import com.dchh.android.suverynew.http.CommonAction0;
import com.dchh.android.suverynew.http.CommonSubscriber;
import com.dchh.android.suverynew.http.RetrofitManager;
import com.dchh.android.suverynew.http.services.ICommonService;
import com.dchh.android.suverynew.module.http.ICommonModule;
import com.dhcc.android.base.utils.version.UpdataInfo;

import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by eric on 2016/8/6.
 */
public class CommonModule implements ICommonModule {
    private ICommonModelListener mCommonModeListener;
    private ICommonService mCommonService;

    public CommonModule(ICommonModelListener mCommonModeListener) {
        this.mCommonModeListener = mCommonModeListener;
        this.mCommonService = RetrofitManager.newInstance().getRetrofit().create(ICommonService.class);
    }

    @Override
    public void checkVersion() {
        this.mCommonService.checkVersion()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnSubscribe(new CommonAction0(this.mCommonModeListener))
                .subscribeOn(AndroidSchedulers.mainThread())
                .subscribe(new CommonSubscriber<UpdataInfo>(this.mCommonModeListener) {
                    @Override
                    public void onNext(UpdataInfo updataInfo) {
                        mCommonModeListener.onCheckVersionSuccess(updataInfo);
                    }
                });

    }
}
